<!-- 主体部分 -->
<template>
  <div class="music-content">
    <div class="music-content-left">
      <ul>
        <li class="music-content-item" v-for="item in songList" :key="item.id">
          <span class="list-item-left" @click="getSong(item.id)"></span>
          <span class="list-item-mid">{{ item.name }}</span>
          <span
            :class="['list-item-right', { hidden: item.mvid === 0 }]"
            @click="getMv(item.mvid)"
          ></span>
        </li>
      </ul>
    </div>
    <div :class="['music-content-mid', { imghidden: !isImgShow }]">
      <img
        :class="{ playing: isaudioplaying }"
        src="../assets/images/player_bar.png"
        alt=""
      />
      <img :src="picUrl" alt="" />
      <img
        :class="{ autorotate: isaudioplaying }"
        src="../assets/images/disc.png"
        alt=""
      />
    </div>
    <div class="music-content-right">
      <h2 :class="{ imghidden: !isImgShow }">热门评论</h2>
      <ul>
        <li
          class="comment-item"
          v-for="item in commentUrl"
          :key="item.commentId"
        >
          <img :src="item.user.avatarUrl" alt="" />
          <span>{{ item.user.nickname }}</span>
          <p>{{ item.content }}</p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  props: {
    songList: {
      type: Array,
      default: function () {
        return [];
      },
    },
    isaudioplaying: {
      type: Boolean,
      default: false,
    },
    isImgShow: {
      type: Boolean,
      default: false,
    },
  },
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      picUrl: "",
      audioPlaying: false, //歌曲播放的状态
      commentUrl: [],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {
    isAudioPlaying: function (newVal) {
      this.audioPlaying = newVal;
    },
  },
  //方法集合
  methods: {
    getSong: async function (id) {
      // 歌曲正在播放
      this.audioPlaying = true;
      // 请求获取歌曲的地址
      let res = await this.$http.get("song/url", {
        params: {
          id: id,
        },
      });
      // console.log(res);
      let songUrl = res.data.data[0].url;
      this.$emit("geturl", songUrl);
      // 请求获取封面图片
      let res2 = await this.$http.get("song/detail", {
        params: {
          ids: id,
        },
      });
      // console.log(res2.data.songs[0].al.picUrl);
      this.picUrl = res2.data.songs[0].al.picUrl;
      // this.$emit("getpicurl", picUrl);
      // 请求获取热门评论
      let res3 = await this.$http.get("comment/hot", {
        params: {
          type: 0,
          id: id,
        },
      });
      console.log(res3);
      this.commentUrl = res3.data.hotComments;
    },
    getMv: async function (mvid) {
      let res = await this.$http.get("mv/url", {
        params: {
          id: mvid,
        },
      });
      console.log(res);
      let mvUrl = res.data.data.url;
      this.$emit("getmvurl", mvUrl);
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less'  scoped>
@keyframes running {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
li {
  list-style: none;
}
.music-content {
  width: 100%;
  height: 100%;
  display: flex;
  .music-content-left::after {
    content: "";
    width: 1px;
    height: 480px;
    position: absolute;
    left: 200px;
    top: 0;
    background: linear-gradient(white, gray, blue, gray, white);
  }
  .music-content-left {
    height: 100%;
    display: inline-block;
    position: relative;
    width: 200px;
    ul {
      height: 480px;
      overflow-x: hidden;
      overflow-y: auto;
      .music-content-item {
        width: 200px;
        height: 40px;
        .list-item-left {
          width: 25px;
          height: 25px;
          display: inline-block;
          background: url(../assets/images/table.png) -18px -18px;
        }

        .list-item-mid {
          color: #fff;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          display: inline-block;
          text-align: center;
          width: 115px;
          height: 30px;
          line-height: 40px;
        }
        .hidden {
          visibility: hidden;
        }
        .list-item-right {
          display: inline-block;
          width: 30px;
          height: 20px;
          background: url(../assets/images/table.png) left -45px;
        }
      }
    }
  }
  .imghidden {
    visibility: hidden;
  }
  .music-content-mid {
    display: inline-block;
    position: relative;
    width: 400px;
    height: 100%;
    .playing {
      transform: rotate(0deg) !important;
    }
    img:nth-child(1) {
      position: absolute;
      z-index: 11;
      left: 200px;
      top: 0;
      display: block;
      width: 92px;
      height: 128px;
      left: 200px;
      position: absolute;
      transform: rotate(-25deg);
      transform-origin: 12px 12px;
      transition: all 2s;
    }
    img:nth-child(2) {
      position: absolute;
      z-index: 9;
      left: 141px;
      top: 142px;
      display: block;
      width: 150px;
      height: 150px;
    }
    .autorotate {
      animation-name: running;
      animation-duration: 5s;
      animation-timing-function: linear;
      animation-iteration-count: infinite;
    }
    img:nth-child(3) {
      z-index: 10;
      position: absolute;
      left: 90px;
      top: 95px;
      display: block;
      width: 254px;
      height: 255px;
    }
  }
  .music-content-right::before {
    content: "";
    width: 1px;
    height: 480px;
    position: absolute;
    left: -5px;
    top: 0;
    background: linear-gradient(white, gray, blue, gray, white);
  }
  .music-content-right {
    display: inline-block;
    position: relative;
    width: 200px;
    height: 100%;
    h2 {
      font-size: 20px;
      line-height: 30px;
    }
    ul {
      height: 480px;
      overflow-x: hidden;
      overflow-y: auto;
      .comment-item {
        img {
          width: 35px;
          height: 35px;
          vertical-align: middle;
          margin-right: 10px;
          border-radius: 50%;
        }

        span {
          vertical-align: middle;
        }

        p {
          padding: 5px;
          color: #fff;
        }
      }
    }
  }
}
</style>